import { Effect, ImmerReducer, Reducer, Subscription } from 'umi';

export interface HeroModelState {
    partners: any,
    restrained: any,
    restraint: any,
    usageTips: string,
    battleTips: string,
    teamTips: string,
    shipin: any,
    skins: any,
    downWind: any,
    upWind: any,
    skills: any,
    name: string,
    title: string,
    cate: Array<string>,
    scores: any,
    avatar: string,
    banner: string,
    photo: string,
}

export interface HeroModelType {
    namespace: 'heroCard';
    state: HeroModelState;
    reducers: {
        // save: Reducer<IndexModelState>;
        // 启用 immer 之后
        addCard: ImmerReducer<HeroModelType>;
        delCard: ImmerReducer<HeroModelType>;
        setCard: ImmerReducer<HeroModelType>;
        setSkillCard: ImmerReducer<HeroModelType>;
        setShipinVal: ImmerReducer<HeroModelType>;
        addSkin: ImmerReducer<HeroModelType>;
        delSkin: ImmerReducer<HeroModelType>;
        setSkinItem: ImmerReducer<HeroModelType>;
        changeEquip: ImmerReducer<HeroModelType>;
        addSkill: ImmerReducer<HeroModelType>;
        delSkill: ImmerReducer<HeroModelType>;
        changeSkillItem: ImmerReducer<HeroModelType>;
        changeHeroInfo: ImmerReducer<HeroModelType>;
        changeScoresType: ImmerReducer<HeroModelType>;
        upLoadHeroInfo: ImmerReducer<HeroModelType>;
        promotionMp4: ImmerReducer<HeroModelType>;
    };
}

const HeroModel: HeroModelType = {
    namespace: 'heroCard',
    state: {
        name: "",
        title: "",
        cate: [],
        partners: [],
        restrained: [],
        restraint: [],
        usageTips: "",
        battleTips: "",
        teamTips: "",
        shipin: {
            title: "",
            video: "",
            submit: "",
            fan: null,
            view: null,
        },
        skins: [],
        downWind: {
            equipment: [],
            tips: ""
        },
        upWind: {
            equipment: [],
            tips: ""
        },
        skills: [],
        scores: {
            attack: null,
            difficulty: null,
            skill: null,
            survive: null
        },
        avatar: "",
        banner: "",
        photo: ""
    },
    reducers: {
        changeHeroInfo(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState[action.classify] = action.value
            return NewState
        },
        promotionMp4(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState.shipin.video = action.value
            return NewState
        },
        addCard(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState[action.com].push({})
            return NewState
        },
        delCard(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState[action.com].splice(action.index, 1)
            return NewState
        },
        setCard(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState[action.com][action.index][action.heroType] = action.value
            return NewState
        },
        setSkillCard(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState[action.com] = action.value
            return NewState
        },
        setShipinVal(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState.shipin[action.com] = action.value
            return NewState
        },
        addSkin(state) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState.skins.push({
                img: "",
                name: ""
            })
            return NewState
        },
        delSkin(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState.skins.splice(action.index, 1)
            return NewState
        },
        setSkinItem(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState.skins[action.index][action.com] = action.value
            return NewState
        },
        changeEquip(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState[action.com][action.prop] = action.value
            return NewState
        },
        addSkill(state) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState.skills.push({})
            return NewState
        },
        delSkill(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState.skills.splice(action.index, 1)
            return NewState
        },
        changeSkillItem(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState.skills[action.index][action.classify] = action.value
            return NewState
        },
        changeScoresType(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState.scores[action.classify] = action.value
            return NewState
        },
        upLoadHeroInfo(state, action) {
            let NewState = JSON.parse(JSON.stringify(state))
            NewState[action.classify] = action.value
            return NewState
        }
    }
};

export default HeroModel;